package com.gupaoedu.starter.autoconfiguration;

import com.gupaoedu.starter.format.FormatProcessor;
import com.gupaoedu.starter.format.JsonFormat;
import com.gupaoedu.starter.format.StringFormat;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

/**
 * @Author: JLL
 * @Date: 2019/7/8 23:03
 */

@Configuration
public class FormatAutoConfiguration {

    @ConditionalOnMissingClass("com.alibaba.fastjson.JSON")  //如果当前classpath里没有这个类，就注入StringFormat这个实例。
    @Bean
    @Primary
    public FormatProcessor stringFormat(){
        return new StringFormat();
    }

    @ConditionalOnClass(name = "com.alibaba.fastjson.JSON") // 如果当前classpath里存在这个类，就注入JsonFormat这个实例
    @Bean
    public FormatProcessor jsonFormat(){
        return new JsonFormat();
    }



}
